package com.jk.blog.controller;

import com.jk.blog.model.ResponseInfo;
import com.jk.blog.service.AccountService;
import com.jk.blog.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class AccountController {
    
    @Autowired
    private AccountService accountService;

    /**
     * 用户登录
     * @param loginAccount  登录账号
     * @param password      登录密码
     * @return
     */
    @RequestMapping(value="/login", method=RequestMethod.GET)
    public ResponseInfo login(String loginAccount, String password){
        return accountService.queryLoginUserInfo(loginAccount, password);
    }

    /**
     * 获取登录账号信息详情
     * 标签association，一对一使用示例
     * @param id
     * @return
     */
    @RequestMapping(value = "/accountDetail/{id}", method = RequestMethod.GET)
    public ResponseInfo queryAccountDetail(@PathVariable Integer id){
        return accountService.queryAccountDetail(id);
    }

    /***
     * 用户注册
     * @param   loginAccount      登录账号
     * @param   loginEmail        邮箱
     * @param   password          密码
     * @param   confirmPassword   确认密码
     * @return
     */
    @RequestMapping(value="/register", method=RequestMethod.POST)
    public ResponseInfo register(@RequestParam String loginAccount, @RequestParam String loginEmail,
                                 @RequestParam String password, @RequestParam String confirmPassword){
        if(StringUtils.isNotEqual(password, confirmPassword)){
            return new ResponseInfo(2000003, "密码不一致，请重新输入！");
        }
        return accountService.addRegisterInfo(loginAccount, loginEmail, password);
    }


    /**
     * TODO 注销登录
     * @return
     */
    @RequestMapping(value="/logout", method=RequestMethod.GET)
    public ResponseInfo logout(){
        return ResponseInfo.SUCCESS;
    }
}
